//
//  HQualityThreeViewController.m
//  NursingManages
//
//  Created by Zhen Huang on 17/11/14.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HQualityThreeViewController.h"
#import "HQc_codeModel.h"
#import "InitDbTable.h"
#import "HQualityDetailViewController.h"
#import "HQCSpecificViewController.h"
#import "Model_Hr_InspectDetail_New.h"
@interface HQualityThreeViewController ()
<UITableViewDelegate,
UITableViewDataSource>
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, copy)NSString *dept_id;
@property (nonatomic, strong) UITableView *tableview;
@end

@implementation HQualityThreeViewController


- (instancetype)initWithDataArray:(NSArray *)dataArray {
    if (self) {
        self.dataArray = dataArray;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableview];
    
    InitDbTable* ins = [[InitDbTable alloc]init];
    
    [InitDbTable sharedFMDBManeger];
    
    NSArray *array  = [ins getPar_id:self.result_id check_flag:1];

    if (array.count > 0) {
        
        for (int i = 0; i < self.dataArray.count; i++) {
            
            HQc_codeModel *model = self.dataArray[i];
            for (int j = 0; j < array.count; j ++) {
                
                Model_Hr_InspectDetail_New *detailModel = array[j];
                
                if ([model.CODE_ID isEqualToString:detailModel.par_id]) {
                    
                    model.check_flag = 1;
                }
            }
        }
   
    }
}

- (UITableView *)tableview
{
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight) style:UITableViewStylePlain];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.tableFooterView = [[UIView alloc]init];
        [_tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableview;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    HQc_codeModel *model = self.dataArray[indexPath.row];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    if (model.check_flag == 1) {
     
        cell.textLabel.textColor = [UIColor redColor];
    }
    
    NSRange range = [model.CODE_NAME rangeOfString:@"、"];
    
    NSString * CodeName = [model.CODE_NAME substringFromIndex:range.location + 1];
    
    cell.textLabel.text = CodeName;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    InitDbTable* ins = [[InitDbTable alloc]init];
    [InitDbTable sharedFMDBManeger];
    HQc_codeModel *model = self.dataArray[indexPath.row];
    NSMutableArray *pushArray = [NSMutableArray new];
    
    NSMutableArray *detailArray = [ins Qc_codeDetail:model.TYPE_ID STANDARD_ID:model.STANDARD_ID par_id:model.CODE_ID];
    pushArray = detailArray;
    
    if ([model.PROBLEM_COLLECTION_FLAG isEqualToString:@"1"]) {
        
        HQCSpecificViewController *HQCSVC = [[HQCSpecificViewController alloc]initWithSpecificMoel:model Section:indexPath.section dataArray:pushArray level_id:[self.menuParam objectForKey:@"LEVEL_ID"]];
        HQCSVC.title = @"请输入具体情况";
        HQCSVC.result_id = self.result_id;
        HQCSVC.type = 4;
        HQCSVC.par_id = model.CODE_ID;
        HQCSVC.getBlockInspect = ^(NSString *dept_id) {
            
            self.dept_id = dept_id;
        };

        [self.navigationController pushViewController:HQCSVC animated:YES];

    }else {
        
        HQCSpecificViewController *HQCSVC = [[HQCSpecificViewController alloc]initWithSpecificMoel:self.codeModel Section:indexPath.section dataArray:pushArray level_id:[self.menuParam objectForKey:@"LEVEL_ID"]];
        HQCSVC.title = @"请输入具体情况";
        HQCSVC.result_id = self.result_id;
        HQCSVC.type = 4;
        HQCSVC.par_id = model.CODE_ID;
        HQCSVC.getBlockInspect = ^(NSString *dept_id) {
          
            self.dept_id = dept_id;
        };

        [self.navigationController pushViewController:HQCSVC animated:YES];

    }
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
